# coding:utf-8
import random
import json
import requests
"""
@author:Yang Fan
@个人网站:https://www.heroyf.club
"""

"""bilibili评论抽奖脚本"""


def choose_winner(av):
    usernames = set()
    url = 'https://api.bilibili.com/x/v2/reply?type=1&oid='+av+'&pn='
    count = 1
    replies = json.loads(requests.get(url+str(count)).text)['data']['replies']
    # print(replies)

    print("-------载入所有评论-------")
    while replies is not None:
        for i in range(len(replies)):
            username = replies[i]['member']['uname']
            print(username)
            usernames.add(username)
        count += 1
        replies = json.loads(requests.get(
            url + str(count)).text)['data']['replies']
    print("-------开奖中﻿ε≡٩(๑>₃<)۶-------")
    wtf = random.sample(usernames, 1)[0]
    print("一共有"+str(len(usernames))+"名同学参与评论")
    print("恭喜 "+wtf+" 这位同学中奖")


if __name__ == '__main__':
    av = input("输入你要抽奖的av号:")
    choose_winner(av)
